.PHONY:com list lint sim build wave clean 

DEFINE_DIR   := ./src
RTL_DIR      := ./src
SIM_DIR      := ./sim
TOP_MODULE   := mycpu
RTL_FILES    := rtl.f
#-------------------------------------------------------------------------------------------------------
com  : clean list build 
#-------------------------------------------------------------------------------------------------------

list	:
	@echo  "#-------------Source-------------" > $(RTL_FILES)

	@find ./rtl -name '*.v' -o -name '*.sv'>> $(RTL_FILES)


lint    :
	verilator --lint-only $(RTL_DIR)/$(TOP_MODULE).sv\
			+incdir+$(DEFINE_DIR) \
			--Wno-MODDUP  \
		 	-f $(RTL_FILES) 


build   :   
	verilator -Wall --trace -cc $(RTL_DIR)/$(TOP_MODULE).sv \
			--Wno-MODDUP  \
			+incdir+$(DEFINE_DIR) \
			-f $(RTL_FILES) 	\
            --exe $(SIM_DIR)/$(TOP_MODULE).cpp  


sim		:
	@make -C obj_dir -f V$(TOP_MODULE).mk V$(TOP_MODULE)	
	@echo "### SIMULATING ###"
	./obj_dir/V$(TOP_MODULE)

wave	:
	@echo
	@echo "### WAVES ###"
	gtkwave waveform.vcd


clean  :
	rm -rf obj_dir *.vcd *.log *.f
#-------------------------------------------------------------------------------------------------------
